class Solution {
public:
    int findLHS(vector<int>& nums) {
        if(nums.size()==0 || nums.size()==1){return 0;}
        map<int,int>mp;
        vector<int>cnt;
        vector<int>number;
        for(int i=0;i<nums.size();i++){
            mp[nums[i]]++;
        }
        for(map<int,int>::iterator iter=mp.begin();iter!=mp.end();iter++){
            number.push_back(iter->first);
            cnt.push_back(iter->second);
        }
        int ans=0;
        for(int i=0;i<cnt.size()-1;i++){
            if(abs(number[i]-number[i+1])!=1){continue;}
            ans=max(ans,cnt[i]+cnt[i+1]);
        }
        return ans;
    }
};